package com.thinkersre;

import com.thinkersre.event.mail.Mail;
import com.thinkersre.event.mail.MailProducer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;


@RunWith(SpringRunner.class)
    @SpringBootTest
    @ContextConfiguration(classes = ThinkersReWebApplication.class)
    public class MailTestSecond {
        @Autowired
        private MailProducer mailProducer;

        @Autowired
        private TemplateEngine templateEngine;

        @Test
        public void testHtmlMail() {
            Context context = new Context();
            context.setVariable("username", "sunday");

            String content = templateEngine.process("/mail/demo.html", context);
            Mail mail = new Mail();
            mail.setContent(content);
            mail.setTo("920774923@qq.com");
            mail.setSubject("网站测试第二轮！");
            System.out.println(content);
            mailProducer.fireMail(mail);
        }

    }
